package com.roc.web.action.estrn;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

public class EstrnStasticsSearchCondition extends BaseSearchCondition{
	
	private String minDate;//起始日期
	
	private String maxDate;//结束日期
	
	private String dateFlag;//1 历史表    2临时表
	
	private String areaId;//大区id
	
	private String orgCode;//机构号
	
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {

		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		
		if("-1".equals(areaId)){
			filedBeanList.add(new WhereHQLFieldBean("tb.BANK_BELONG_CD", orgCode, "=", false));
		}
		
		if(Constance.isNotEmpty(minDate)){
         	filedBeanList.add(new WhereHQLFieldBean("t.TRANS_DT",minDate.trim(),">=", false));
       	}
		
		
		if(Constance.isNotEmpty(maxDate)){
         	filedBeanList.add(new WhereHQLFieldBean("t.TRANS_DT",maxDate.trim(),"<=", false));
       	}
		
		return filedBeanList;
	}

	@Override
	protected String getRowCountHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select count(1) ")
			.append("from TBL_MCHT_INF tb ")
			.append("inner join ");
		if("1".equals(dateFlag)){//1 历史表    2临时表
			sb.append("apstfr.tbl_tfr_his_trn_log ");
		}
		if("2".equals(dateFlag)){
			sb.append("hbat.tbl_tfr_trn_log ");
		}
		sb.append(" t  on tb.mcht_cd = t.MCHNT_CD ")
			.append("where t.RESP_CD = '00' AND t.trans_st = '1000000000' AND trim(T.MA_TRANS_CD) IN ('1011', '1171') ");
		if(!("-1").equals(areaId)){
			sb.append("and exists (select 1 from tbl_org_main e where e.area_id="+areaId+" and e.org_code=tb.uc_bc_cd_area)");
		}
		return sb.toString();
	}

	@Override
	protected String getSearchHQL() {
		StringBuffer sb = new StringBuffer();
		sb.append("select (select b.name from tbl_org_main d,tbl_area b where b.id=d.area_id and d.org_code=tb.uc_bc_cd_area) companyName, ")
			.append("(select c.org_name from tbl_org_main c where c.org_code= tb.uc_bc_cd_area) oneAgentName, ")
			.append("t.trans_at, t.ma_trans_cd, t.TRANS_DT, ")
			.append("(case  when t.card_class = '01' then  '借记卡'  else '信用卡' end) cardType,t.pos_entry_md_cd ")
			.append("from TBL_MCHT_INF tb ")
			.append("inner join ");
		if("1".equals(dateFlag)){//1 历史表    2临时表
			sb.append("apstfr.tbl_tfr_his_trn_log ");
		}
		if("2".equals(dateFlag)){
			sb.append("hbat.tbl_tfr_trn_log ");
		}
		sb.append(" t  on tb.mcht_cd = t.MCHNT_CD ")
			.append("where t.RESP_CD = '00' AND t.trans_st = '1000000000' AND trim(T.MA_TRANS_CD) IN ('1011', '1171') ");
		if(!("-1").equals(areaId)){
			sb.append("and exists (select 1 from tbl_org_main e where e.area_id="+areaId+" and e.org_code=tb.uc_bc_cd_area)");
		}
		return sb.toString();
	}

	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return " ORDER BY t.TRANS_DT DESC, t.TRANS_MT DESC";
	}

	public String getMinDate() {
		return minDate;
	}

	public void setMinDate(String minDate) {
		this.minDate = minDate;
	}

	public String getMaxDate() {
		return maxDate;
	}

	public void setMaxDate(String maxDate) {
		this.maxDate = maxDate;
	}

	public String getDateFlag() {
		return dateFlag;
	}

	public void setDateFlag(String dateFlag) {
		this.dateFlag = dateFlag;
	}

	public String getAreaId() {
		return areaId;
	}

	public void setAreaId(String areaId) {
		this.areaId = areaId;
	}

	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}
	
}
